package com.cogent.dynamicform.form.impl;

import java.util.HashMap;

import com.cogent.business.helper.QuerySelectHelper;
import com.cogent.common.util.MapUtil;
import com.cogent.dynamicform.domain.BaseFormColumnDomain;
import com.cogent.dynamicform.domain.FormColumnDomain;
import com.cogent.dynamicform.form.AbstractDynamicForm;
import com.opensymphony.oscache.util.StringUtil;

public class MutiQuerySelectDynamicFormImpl extends AbstractDynamicForm {
	public String genQueryField(BaseFormColumnDomain formColumnDomain, HashMap formMap) {
		return "";
	}
	
	public String genInputField(FormColumnDomain formColumnDomain, HashMap formMap) {
		if(formColumnDomain.getViewmodel() > 0)
			return getShowValue(formColumnDomain, formMap) + "&nbsp;";
		StringBuffer str = new StringBuffer();
		String name = formColumnDomain.getName();
		str.append(QuerySelectHelper.getMutilSelect(formColumnDomain.getTypecode(), name, formMap));
		str.append("<input type=\"hidden\" name=\"").append(name).append("\" id=\"").append(name)
			.append("\" value=\"").append(MapUtil.getStringValue(formMap, name)).append("\"/>");
		
		return str.toString();
	}	
	
	public String getShowValue(BaseFormColumnDomain formColumnDomain, HashMap formMap) {
		if(formColumnDomain.getShowtype() == 1)
			return "&nbsp;";
		String name = formColumnDomain.getName();
		if(name.indexOf(".") > 0)
			name = name.substring(name.indexOf(".") + 1);
		String ret = QuerySelectHelper.getMutilSelectValue(formColumnDomain.getTypecode(), name, formMap);
		if(StringUtil.isEmpty(ret))
			ret = "&nbsp;";
		return ret;
	}
}